#pragma once

#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

const std::string gpipefile = "./fifo";
const mode_t gmode = 0600;
const int gdefault_fd = -1;
const int gsize = 1024;
const int gForRead = O_RDONLY;
const int gForWrite = O_WRONLY; 

int OpenPipe(int flag)
{
	// 读端打开文件时，写端还没打开，读端对应的open会阻塞
	int fd = ::open(gpipefile.c_str(), flag);
	if (fd < 0)
	{
		std::cerr << "open error" << std::endl;
		return false;
	}
	return fd; 
}

void ClosePipeHelper(int fd) 
{
	if (fd >= 0)
		::close(fd);
}